package cn.edu.zzuli.nothinglink.controller;


import cn.edu.zzuli.nothinglink.anno.CurrentUser;
import cn.edu.zzuli.nothinglink.entity.R;
import cn.edu.zzuli.nothinglink.service.WorkPostponeService;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author suzyyy
 * @since 2021-04-08
 */
@RestController
@RequestMapping("/work-postpone")
public class WorkPostponeController {

    @Autowired
    WorkPostponeService workPostponeService;

    @GetMapping("/get/{isStu}")
    public R getPostpone(@PathVariable boolean isStu, @CurrentUser Integer id) {
        return workPostponeService.getWorkPostpone(isStu, id);
    }

    @GetMapping("/condition/{wpId}")
    public R getWorkPostponeCondition(@PathVariable Integer wpId) {
        return workPostponeService.getWorkPostponeCondition(wpId);
    }

    @PutMapping("/decide/{wpId}")
    public R decideThePostpone(@PathVariable Integer wpId, @RequestBody JSONObject json) {
        if (json.get("isAgree") == null ||
                (json.getBoolean("isAgree") == true && json.get("time") == null))
            return R.error().add("error", "请检查参数");
        return workPostponeService.decideThePostpone(wpId, json);
    }

}

